<?php
/**
 * Created by PhpStorm.
 * User: david
 * Date: 3/19/19
 * Time: 6:24 PM
 */

namespace App\Transformers;


use App\Models\User;
use League\Fractal\TransformerAbstract;

class UserTransformer extends TransformerAbstract
{
    protected $defaultIncludes = ['roles'];

    public function transform(User $user)
    {
        return [
            'id' => $user->id,
            'name' => $user->name,
            'email' => $user->email,
            'name_email' => $user->name.'('.$user->email.')',
        ];
    }

    public function includeRoles(User $user)
    {
        return $this->collection($user->roles, new UserRoleTransformer());
    }
}